/*
 * Saphre - Suffix Arrays for Phrase Extraction
 * Copyright (C) 2013 
 * Dale Gerdemann - Tübingen, Germany 
 * Niko Schenk - Frankfurt am Main, Germany
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package util.tokenization_io;

import saphre.core.Store;
import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;
import util.sedgewick.In;

/**
 * A general interface for specifying classes of tokens. 
 * Classes are arbitrary names, which programs can interpret in any way.
 * This should be expanded over time.
 * 
 * A "boundary" is a token that is not allowed to occur in the bridge part
 * between the left part and right part of a gappy phrase.
 */
public class BoundarySymbols implements Serializable {

    Set<Integer> rejectInt = new TreeSet<Integer>();
    Set<String> rejectStr = new TreeSet<String>();

    public BoundarySymbols() {
    }

    public BoundarySymbols(Store store, String filename) {
        In in = new In(filename);
        if (in.exists()) {
            while (!in.isEmpty()) {
                String c = in.readLine();
                rejectStr.add(c);
                rejectInt.add(store.wordToIntChecked(c));
            }
        }
   //     System.out.println("boundaries:" + rejectStr);
    }

    public boolean userSentinel(String tok) {
        return rejectStr.contains(tok);
    }

    public boolean userSentinel(int tok) {
        return rejectInt.contains(tok);
    }

    /**
     * userAnchor is actually a stub. 
     * It can be used to define any kind of class
     * of tokens.
     */
    public boolean userAnchor(String tok) {
        return false;
    }

    public boolean userAnchor(int tok) {
        return false;
    }
    
    @Override
    public String toString() {
        return rejectStr.toString();
    }
}
